package com.ytjj.qmyx.admin.service.impl;

import com.github.pagehelper.PageHelper;
import com.ytjj.common.api.CommonPage;
import com.ytjj.qmyx.admin.mapper.PushTaskMapper;
import com.ytjj.qmyx.admin.model.PushMessage;
import com.ytjj.qmyx.admin.model.PushTask;
import com.ytjj.qmyx.admin.model.vo.PushTaskVO;
import com.ytjj.qmyx.admin.service.PushTaskService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

@Service
public class PushTaskServiceImpl implements PushTaskService {

    @Resource
    private PushTaskMapper pushTaskMapper;

    @Override
    public CommonPage selectPushTaskPage(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<PushTaskVO> pushTaskVOList=pushTaskMapper.selectPushTaskPage();
        List<PushMessage> pushMessages;
        for(PushTaskVO pushTaskVO : pushTaskVOList ){
            List<String> arr = Arrays.asList(pushTaskVO.getPushMessageId().split(","));
            pushMessages = pushTaskMapper.selectPushMessage(arr);
            pushTaskVO.setPushMessages(pushMessages);
        }
        return CommonPage.restPage(pushTaskVOList);
    }

    @Override
    public int insertPushTask(PushTask pushTask) {
        return pushTaskMapper.insertPushTask(pushTask);
    }

    @Override
    public PushTaskVO selectPushTask(Integer id) {
        return pushTaskMapper.selectPushTask(id);
    }

    @Override
    public int updatePushTask(PushTask pushTask) {
        return pushTaskMapper.updatePushTask(pushTask);
    }
}
